import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreWeappAuthService extends BaseService<any> {
  private readonly logger = new Logger(CoreWeappAuthService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * session
   * 对应 PHP: CoreWeappAuthService_core::session()
   * 逻辑类型: undefined - undefined
   */
  async session(site_id: number, code: number) {
    // 基于PHP真实逻辑: session
    // PHP原文: $config = ( new CoreWeappConfigService() )->getWeappConfig($site_id);         if ($config[ 'is_authorization' ]) {             return CoreOplatformSer...
const config = ( this.coreWeappConfigService ).getWeappConfig(site_id);
        if (config[ 'is_authorization' )) {
            return CoreOplatformService.codeToSession(site_id, code);
  }

  /**
   * decryptData
   * 对应 PHP: CoreWeappAuthService_core::decryptData()
   * 逻辑类型: undefined - undefined
   */
  async decryptData(site_id: number, session: number, iv: number, encrypted_data: number) {
    // 基于PHP真实逻辑: decryptData
    // PHP原文: $utils = CoreWeappService::app($site_id)->getUtils();         return $utils->decryptSession($session, $iv, $encrypted_data);     }      /**      * 获取用...
const utils = CoreWeappService.app(site_id).getUtils(];
        return utils.decryptSession(session, iv, encrypted_data);
    }

    /**
     * 获取用户手机号
     * @param int site_id
     * @param string code
     * @return \EasyWeChat\Kernel\HttpClient\Response|\Symfony\Contracts\HttpClient\ResponseInterface
     * @throws InvalidArgumentBusinessException
     * @throws \Symfony\Contracts\HttpClient\BusinessException\TransportBusinessExceptionInterface
     */
    async getUserPhoneNumber(int site_id, string code)
    {
        const api = CoreWeappService.appApiClient(site_id];
        CoreWeappService.refreshToken(site_id); // 为防止多次拒绝手机号的情况，需要刷新token
        return api.postJson('wxa/business/getuserphonenumber', [
            code: (string) code
        ];
  }
  }

  /**
   * getUserPhoneNumber
   * 对应 PHP: CoreWeappAuthService_core::getUserPhoneNumber()
   * 逻辑类型: undefined - undefined
   */
  async getUserPhoneNumber(site_id: number, code: number) {
    // 基于PHP真实逻辑: getUserPhoneNumber
    // PHP原文: $api = CoreWeappService::appApiClient($site_id);         CoreWeappService::refreshToken($site_id); // 为防止多次拒绝手机号的情况，需要刷新token         return $api->pos...
const api = CoreWeappService.appApiClient(site_id];
        CoreWeappService.refreshToken(site_id); // 为防止多次拒绝手机号的情况，需要刷新token
        return api.postJson('wxa/business/getuserphonenumber', [
            code: (string) code
        ];
  }
  }
}
